<template>
  <el-form ref="form" :model="parentInfo" :rules="rules" label-width="80px">
    <el-form-item v-show="false" label="id" prop="id">
      <el-input v-model="parentInfo.id" />
    </el-form-item>
    <el-form-item label="父亲" prop="fName">
      <el-input v-model="parentInfo.fName" />
    </el-form-item>
    <el-form-item label="母亲" prop="mName">
      <el-input v-model="parentInfo.mName" />
    </el-form-item>
    <el-form-item label="父亲电话" prop="fPhone">
      <el-input v-model="parentInfo.fPhone" />
    </el-form-item>
    <el-form-item label="母亲电话" prop="mPhone">
      <el-input v-model="parentInfo.mPhone" />
    </el-form-item>
    <el-form-item label="父亲职业" prop="fJob">
      <el-input v-model="parentInfo.fJob" maxlength="50" />
    </el-form-item>
    <el-form-item label="母亲职业" prop="mJob">
      <el-input v-model="parentInfo.mJob" maxlength="50" />
    </el-form-item>
    <el-form-item label="父亲单位" prop="fUnit">
      <el-input v-model="parentInfo.fUnit" maxlength="50"/>
    </el-form-item>
    <el-form-item label="母亲单位" prop="mUnit">
      <el-input v-model="parentInfo.mUnit" maxlength="50" />
    </el-form-item>
    <el-form-item>
      <el-button type="primary" size="mini" @click="submit">保存</el-button>
      <el-button type="danger" size="mini" @click="close">关闭</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
import { addParentinfo,updateParentinfo } from "@/api/manage/parentinfo";

export default {
  props: {
    parentInfo: {
      type: Object
    }
  },
  created() {
  },
  data() {
    return {
      curParentInfo:{},
      // 表单校验
      rules: {
        fName: [
          { required: true, message: "父亲姓名不能为空", trigger: "blur" }
        ],
        mName: [
          { required: true, message: "母亲姓名不能为空", trigger: "blur" }
        ],
        fPhone: [
          { required: true, message: "手机号码不能为空", trigger: "blur" },
          {
            pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
            message: "请输入正确的手机号码",
            trigger: "blur"
          }
        ],
        mPhone: [
          { required: true, message: "手机号码不能为空", trigger: "blur" },
          {
            pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
            message: "请输入正确的手机号码",
            trigger: "blur"
          }
        ]
      }
    };
  },
  methods: {
    submit() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if(this.parentInfo.id){
            updateParentinfo(this.parentInfo).then(response => {
              this.msgSuccess("修改成功");
            });
          }else {
            addParentinfo(this.parentInfo).then(() => {
              this.msgSuccess("修改成功");
            });
          }
        }
      });
    },
    close() {
      // this.$store.dispatch("tagsView/delView", this.$route);
       //this.$router.push({ path: "/index" });
      this.$router.back(-1)
    }
  }
};
</script>
